package com.example.demo.controller;

import com.example.demo.config.Poi;
import com.example.demo.entity.Record;
import com.example.demo.service.Recordservice;
import excel.POIConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("record")
public class RecordController {

    @Autowired
    Recordservice recordservice;


    //存当前答卷的人的基本信息
    @RequestMapping("save")
    public Integer add(@RequestBody Record record){
        recordservice.add(record);
        return 56;
    }
    //点击最终答卷
    @RequestMapping
    public String record(Record record){ return "record"; }
    //点击最终答卷
    @RequestMapping("update")
    @ResponseBody
    public Record update(HttpSession session){
        System.out.println("");
        Record update = recordservice.update();
        System.out.println(update);
        session.setAttribute("dong",update);
        return update;
    }
    @RequestMapping("getRecord")
    @ResponseBody
    public Record getRecord(HttpSession session){
        Record record =(Record) session.getAttribute("dong");
        return record;
    }




    //查询记录表
    @RequestMapping("getrecord")
    @ResponseBody
    public List<Record> getrecord(HttpSession session){
        Record record= (Record)session.getAttribute("");
        return recordservice.getrecord();
    }



    //导出
    @RequestMapping("export")
    public void export(HttpServletResponse response) throws Exception{
        Poi p = new Poi();
        List list = recordservice.selectByExample(null);
        p.setList(list);
        p.setTitle("会议列表");


        String[] headers = {"id","用户名","性别","年龄","分数","时间"};
        p.setHeaders(headers);
        Object[][] fields = {
                {"sid", POIConstant.AUTO},
                {"name", POIConstant.AUTO},
                {"sex",POIConstant.AUTO},
                {"age",POIConstant.AUTO},
                {"sum",POIConstant.AUTO},
                {"starttime",POIConstant.AUTO},
        };


        p.setFields(fields);
        Poi.getResponse(response);
        p.write(response);
    }





}
